package com.ksoft.utils;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import android.content.Context;
import dalvik.system.DexFile;

public class Pkg {
	public static List<Class<?>> InflateClasses(Context ctx, Package pkg) {
		ArrayList<Class<?>> result = new ArrayList<Class<?>>();
		ClassLoader loader = ctx.getClassLoader();

		try {
			DexFile df = new DexFile(ctx.getPackageCodePath());

			for (Enumeration<String> iter = df.entries(); iter
					.hasMoreElements();) {
				try {
					String s = iter.nextElement();
					Class<?> type = loader.loadClass(s);
					
					if (type.getPackage().equals(pkg))
						result.add(type);
					
				} catch (Exception e) {}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
}
